package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        Class cls = Class.forName("reflect.Person");
        Method method = cls.getMethod("say",String.class,int.class);
        String name = method.getName();
        System.out.println(name);
        //获取参数列表
        Class[] parameterTypes = method.getParameterTypes();
        for(Class parameterType:parameterTypes){
            System.out.println("参数类型："+parameterType.getName());
        }
        //获取参数的个数
        int count = method.getParameterCount();
        System.out.println("参数个数："+count);
        //获取返回值类型
        Class returnType = method.getReturnType();
        System.out.println("返回值类型："+returnType.getName());
        //获取方法的访问修饰符
        int modifiers = method.getModifiers();
        switch (modifiers){
            case Modifier.PUBLIC:
                System.out.println("访问修饰符：public");
                break;
            case Modifier.PRIVATE:
                System.out.println("访问修饰符：private");
                break;
            case Modifier.PROTECTED:
                System.out.println("访问修饰符：protected");
                break;
            default:
                System.out.println("访问修饰符：default");
                break;
        }
    }
}
